{extend name="layout:base" /}{block name="content"}
<?php
$global=isSupperManagerForSession();
?>

<link rel="stylesheet" type="text/css" href="/static/admin/css/style.css" />
<script src="/static/mimi/js/confirm/js/jquery-1.9.1.js"></script>

<link rel="stylesheet" href="/static/mimi/css/animate.min.css" type="text/css" />
<link rel="stylesheet" href="/static/mimi/css/font-awesome.min.css" type="text/css" />


<link rel="stylesheet" href="/static/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="/static/zTree_v3/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="/static/zTree_v3/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript" src="/static/zTree_v3/js/jquery.ztree.exedit.js"></script>
<SCRIPT type="text/javascript">
    <!--
    var setting = {
        view: {
            addHoverDom: addHoverDom,
            removeHoverDom: removeHoverDom,
           // selectedMulti: false
        },
        check: {
           // enable: true,
            //autoCheckTrigger: true,
            //chkStyle:"checkbox"
        },
        edit: {
            enable: true,
            editNameSelectAll: true,
            showRemoveBtn: showRemoveBtn,
            showRenameBtn: showRenameBtn
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onCheck:onCheck,
            beforeDrag: beforeDrag,
            beforeEditName: beforeEditName,
            beforeRemove: beforeRemove,
            beforeRename: beforeRename,
            onRemove: onRemove,
            onRename: onRename
        }
    };

    var zNodes =<?php echo json_encode($lists,true); ?>;
    var log, className = "dark";
    function beforeDrag(treeId, treeNodes) {
        return false;
    }
    function beforeEditName(treeId, treeNode) {
        className = (className === "dark" ? "":"dark");
        showLog("[ "+getTime()+" beforeEditName ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.selectNode(treeNode);
        setTimeout(function() {
            //if (confirm("进入节点 -- " + treeNode.name + " 的编辑状态吗？")) {
                setTimeout(function() {
                    zTree.editName(treeNode);
                }, 0);
            //}
       }, 0);
        return false;
    }

    function beforeRename(treeId, treeNode, newName, isCancel) {
        className = (className === "dark" ? "":"dark");
        showLog((isCancel ? "<span style='color:red'>":"") + "[ "+getTime()+" beforeRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>":""));
        if (newName.length == 0) {
            setTimeout(function() {
                var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                zTree.cancelEditName();
                alert("节点名称不能为空.");
            }, 0);
            return false;
        }
        return true;
    }
    function onRename(e, treeId, treeNode, isCancel) {
        //showLog((isCancel ? "<span style='color:red'>":"") + "[ "+getTime()+" onRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>":""));
        update(treeNode.id,treeNode.name,function(data){
               if(data.err==0)
               {

               }else
               {
                   ErrTiShi(data.msg);return false;
               }
        })
    }
    function showRemoveBtn(treeId, treeNode) {
        return true;//!treeNode.isFirstNode;//第一个节点不能删除
    }
    function showRenameBtn(treeId, treeNode) {
        return true;//!treeNode.isLastNode;//最后一个节点不能重命名
    }
    function showLog(str) {
       console.log(str);
    }
    function getTime() {
        var now= new Date(),
            h=now.getHours(),
            m=now.getMinutes(),
            s=now.getSeconds(),
            ms=now.getMilliseconds();
        return (h+":"+m+":"+s+ " " +ms);
    }

    function addHoverDom(treeId, treeNode) {

        var sObj = $("#" + treeNode.tId + "_span");
        if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
        var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
            + "' title='add node' onfocus='this.blur();'></span>";
        sObj.after(addStr);
        var btn = $("#addBtn_"+treeNode.tId);
        if (btn) btn.bind("click", function(){
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            var tempName = 'new node';
            add(treeNode.id,tempName,function(data){
                zTree.addNodes(treeNode, {id:data.id, pId:data.pId, name:data.name});
                return false;
            })

        });
    };
    function removeHoverDom(treeId, treeNode) {
        $("#addBtn_"+treeNode.tId).unbind().remove();
    };
    function beforeRemove(treeId, treeNode) {
        return confirm("确认要删除节点 -- " + treeNode.name + " 吗？");


    }
    function onRemove(e, treeId, treeNode) {
        del(treeNode.id,function(data){
            if(data.err==0)
            {
                $("#addBtn_"+treeNode.tId).unbind().remove();
                return true;
            }else
            {
                alert(data.msg);
                return false;
            }
        });
    }
    function selectAll() {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.setting.edit.editNameSelectAll =  $("#selectAll").attr("checked");
    }
    function onCheck(treeId, treeNode) {
        //所有选择的都会触发这个函数
    }

    $(document).ready(function(){
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        //$("#selectAll").bind("click", selectAll);
        $("#getAll").click(function(){
            var treeObj=$.fn.zTree.getZTreeObj("treeDemo"),
                nodes=treeObj.getCheckedNodes(true),    v="";
            for(var i=0;i<nodes.length;i++){
                v+=nodes[i].name + ",";
                alert(nodes[i].id); //获取选中节点的值
            }
            console.log(v);
        });
    });
    //-->
</SCRIPT>
<style type="text/css">
    .ztree li span.button.add {margin-left:2px; margin-right: -1px; background-position:-144px 0; vertical-align:top; *vertical-align:middle}
</style>

   
<section class="topBanners">
   <div class="icon"></div>
   <div class="topBannersNav">
   		<span data-url="/admin/hosparticletype/lists" onclick="ContentLoadGo('/admin/hosparticletype/lists')">文章分类</span>
   </div>
</section>
   
<section id="serach_section" style="margin-top:10px;margin-left:auto;margin-right:auto;">

      <input power="30200" type="button" value="添加" class="group_btn add fr" />
      <br style="clear:both;width:0px;height:0px;">
</section>
<section id="content_section" style="margin:10px auto;width:96%;border:1px solid #ccc;padding:10px 10px;">

<div class="content_wrap">
    <div class="zTreeDemoBackground left">
        <ul id="treeDemo" class="ztree"></ul>
    </div>
</div>
</section>
<script type="text/javascript">
function myResearch(){
    var url="/admin/hosparticletype/lists";

    var param={
    };
    ContentLoadGo(url,param);
}


function update(id,name,callback)
{
    var url="/admin/hosparticletype/editData";
    if(name=="")
    {
        ErrTiShi("请输入分类名称");return false;
    }
    var param={
        name:name,
        id:id,
        sys_opt:'addData'//后台判断编辑操作
    };
    AjaxRequest(url,param,function(data){
        if(data.err==0)
        {
            $(".pop_bg").fadeOut();
            $(".pop_bg").html('');

        }
        else
        {

        }
        callback(data.data);
    });
}
function add(pid,name,callback)
{
    var url="/admin/hosparticletype/addData";
    if(name=="")
    {
        ErrTiShi("请输入分类名称");return false;
    }
    var param={
        name:name,
        pid:pid,
        sys_opt:'addData'//后台判断编辑操作
    };
    AjaxRequest(url,param,function(data){
        if(data.err==0)
        {
            $(".pop_bg").fadeOut();
            $(".pop_bg").html('');
            callback(data.data);
        }
        else
        {
            ErrTiShi(data.msg);
        }
    });
}

//删除
function del(id,callback){
    var that =this;
    var url="/admin/hosparticletype/delData";
    var param={
        id:id
    };
    AjaxRequest(url,param,function(data){
        callback(data);
    });
}
$(function(){
 //设置搜索栏
 $(".research").unbind().bind("click",function(){

    myResearch();
 });





//导航
$(".topBannerItem").unbind().bind("click",function(){
   var attArr = $(this).attr();
   goToSelfLink(attArr);

});
//添加
$(".add").unbind().bind("click",function(){
   var that =this;
   var url="/admin/hosparticletype/addData";
   var param={};
    MyContentLoad(url,param);
     //弹出：确认按钮
});

        	   
//全选
$("#all").unbind().bind("click",function(){
    if(this.checked){
        $(".checkBoxInput").attr("checked", true);
        $(".checkBoxInput").prop("checked", true);
    }else{
        $(".checkBoxInput").attr("checked", false);
        $(".checkBoxInput").prop("checked", false);
    }
    var se=getAllSelectItem();
});

});
</script>

{/block}
   